import 'package:eplorex/dao/user_profile_dao.dart';
import 'package:flutter/material.dart';

import '../../constants/color_constants.dart';

class RestPasswordPage extends StatefulWidget {
  const RestPasswordPage({super.key});

  @override
  State<RestPasswordPage> createState() => _RestPasswordPageState();
}

class _RestPasswordPageState extends State<RestPasswordPage> {
  final _formKey = GlobalKey<FormState>();
  String _currentPassword = '';
  String _newPassword = '';
  String _confirmPassword = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(),
        title: Text('设置密码'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Form(
          key: _formKey,
          child: Column(
            // crossAxisAlignment: CrossAxisAlignment.c,
            children: [
              TextFormField(
                decoration: InputDecoration(
                  filled: true,
                  fillColor: Colors.white,
                  hintText: '输入新密码',
                  contentPadding:
                      EdgeInsets.symmetric(vertical: 4, horizontal: 8),
                  border: OutlineInputBorder(
                    gapPadding: 0,
                    borderSide: BorderSide.none,
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                  ),
                ),
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return '请输入新密码';
                  }
                  return null;
                },
                onSaved: (value) => _newPassword = value!,
              ),
              const SizedBox(
                height: 20,
              ),
              TextFormField(
                decoration: InputDecoration(
                  filled: true,
                  fillColor:Colors.white,
                  hintText: '再次输入密码',
                  contentPadding:
                      EdgeInsets.symmetric(vertical: 4, horizontal: 8),
                  border: OutlineInputBorder(
                    borderSide: BorderSide.none,
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                  ),
                ),
                validator: (value) {
                  if (value == null || value.isEmpty) {
                    return '请再次输入密码';
                  }
                  return null;
                },
                onSaved: (value) => _confirmPassword = value!,
              ),
             Padding(padding: EdgeInsets.only(top: 10,bottom: 20),child:  Text('8～20 位密码，至少包含英文字母、数字、特殊符号的2种',
                 style: TextStyle(fontSize: 12)),),
              SizedBox(
                width: MediaQuery.of(context).size.width*0.75,
                child: FilledButton(
                  onPressed: () {
                    _restPassword(_newPassword, _confirmPassword);
                  },
                  child: const Text(
                    '登录',
                  ),
                  style: FilledButton.styleFrom(
                    foregroundColor: Colors.white,
                    backgroundColor: Colors.blue,
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  _restPassword(String _newPassword, String _confirmPassword) {
    UserProfileDao.settingPassword(_confirmPassword, _newPassword);
  }

}
